<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Scheduling Periodic Tasks with Quartz</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/quartz" />
  <meta property="og:title" content="Quarkus - Scheduling Periodic Tasks with Quartz" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/quartz">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Scheduling Periodic Tasks with Quartz</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#architecture">Architecture</a></li>
<li><a href="#solution">Solution</a></li>
<li><a href="#creating-the-maven-project">Creating the Maven project</a></li>
<li><a href="#creating-the-task-entity">Creating the Task Entity</a></li>
<li><a href="#creating-a-scheduled-job">Creating a scheduled job</a>
<ul class="sectlevel2">
<li><a href="#scheduling-jobs-programmatically">Scheduling Jobs Programmatically</a></li>
</ul>
</li>
<li><a href="#updating-the-application-configuration-file">Updating the application configuration file</a></li>
<li><a href="#updating-the-resource-and-the-test">Updating the resource and the test</a></li>
<li><a href="#creating-quartz-tables">Creating Quartz Tables</a></li>
<li><a href="#configuring-the-load-balancer">Configuring the load balancer</a></li>
<li><a href="#setting-application-deployment">Setting Application Deployment</a></li>
<li><a href="#running-the-database">Running the database</a></li>
<li><a href="#run-the-application-in-dev-mode">Run the application in Dev Mode</a></li>
<li><a href="#packaging-the-application-and-run-several-instances">Packaging the application and run several instances</a></li>
<li><a href="#quartz-register-plugin-listeners">Registering Plugin and Listeners</a></li>
<li><a href="#quartz-configuration-reference">Quartz Configuration Reference</a></li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Modern applications often need to run specific tasks periodically.
In this guide, you learn how to schedule periodic clustered tasks using the <a href="http://www.quartz-scheduler.org/">Quartz</a> extension.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>This technology is considered preview.</p>
</div>
<div class="paragraph">
<p>In <em>preview</em>, backward compatibility and presence in the ecosystem is not guaranteed.
Specific improvements might require to change configuration or APIs and plans to become <em>stable</em> are under way.
Feedback is welcome on our <a href="https://groups.google.com/d/forum/quarkus-dev">mailing list</a> or as issues in our <a href="https://github.com/quarkusio/quarkus/issues">GitHub issue tracker</a>.</p>
</div>
<div class="paragraph">
<p>For a full list of possible extension statuses, check our <a href="https://quarkus.io/faq/#extension-status">FAQ entry</a>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
If you only need to run in-memory scheduler use the <a href="scheduler">Scheduler</a> extension.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To complete this guide, you need:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>less than 10 minutes</p>
</li>
<li>
<p>an IDE</p>
</li>
<li>
<p>JDK 1.8+ installed with <code>JAVA_HOME</code> configured appropriately</p>
</li>
<li>
<p>Apache Maven 3.6.2+</p>
</li>
<li>
<p>Docker and Docker Compose installed on your machine</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="architecture"><a class="anchor" href="#architecture"></a>Architecture</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In this guide, we are going to expose one Rest API <code>tasks</code> to visualise the list of tasks created by a Quartz job running every 10 seconds.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="solution"><a class="anchor" href="#solution"></a>Solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We recommend that you follow the instructions in the next sections and create the application step by step.
However, you can go right to the completed example.</p>
</div>
<div class="paragraph">
<p>Clone the Git repository: <code>git clone <a href="https://github.com/quarkusio/quarkus-quickstarts.git" class="bare">https://github.com/quarkusio/quarkus-quickstarts.git</a></code>, or download an <a href="https://github.com/quarkusio/quarkus-quickstarts/archive/master.zip">archive</a>.</p>
</div>
<div class="paragraph">
<p>The solution is located in the <code>quartz-quickstart</code> <a href="https://github.com/quarkusio/quarkus-quickstarts/tree/master/quartz-quickstart">directory</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-maven-project"><a class="anchor" href="#creating-the-maven-project"></a>Creating the Maven project</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First, we need a new project. Create a new project with the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">mvn io.quarkus:quarkus-maven-plugin:1.7.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=quartz-quickstart \
    -DclassName="org.acme.quartz.TaskResource" \
    -Dpath="/tasks" \
    -Dextensions="quartz, hibernate-orm-panache, flyway, resteasy-jsonb, jdbc-postgresql"
cd quartz-quickstart</code></pre>
</div>
</div>
<div class="paragraph">
<p>It generates:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>the Maven structure</p>
</li>
<li>
<p>a landing page accessible on <code><a href="http://localhost:8080" class="bare">http://localhost:8080</a></code></p>
</li>
<li>
<p>example <code>Dockerfile</code> files for both <code>native</code> and <code>jvm</code> modes</p>
</li>
<li>
<p>the application configuration file</p>
</li>
<li>
<p>an <code>org.acme.quartz.TaskResource</code> resource</p>
</li>
<li>
<p>an associated test</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The Maven project also imports the Quarkus Quartz extension.</p>
</div>
<div class="paragraph">
<p>If you already have your Quarkus project configured, you can add the <code>quartz</code> extension
to your project by running the following command in your project base directory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="bash" class="language-bash hljs">./mvnw quarkus:add-extension -Dextensions="quartz"</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will add the following to your <code>pom.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-quartz&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>To use a JDBC store, the <code>quarkus-agroal</code> extension, which provides the datasource support, is also required.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-task-entity"><a class="anchor" href="#creating-the-task-entity"></a>Creating the Task Entity</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In the <code>org.acme.quartz</code> package, create the <code>Task</code> class, with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quartz;

import javax.persistence.Entity;
import java.time.Instant;
import javax.persistence.Table;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

@Entity
@Table(name="TASKS")
public class Task extends PanacheEntity { <i class="conum" data-value="1"></i><b>(1)</b>
    public Instant createdAt;

    public Task() {
        createdAt = Instant.now();
    }

    public Task(Instant time) {
        this.createdAt = time;
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Declare the entity using <a href="https://quarkus.io/guides/hibernate-orm-panache">Panache</a></p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-a-scheduled-job"><a class="anchor" href="#creating-a-scheduled-job"></a>Creating a scheduled job</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In the <code>org.acme.quartz</code> package, create the <code>TaskBean</code> class, with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quartz;

import javax.enterprise.context.ApplicationScoped;

import javax.transaction.Transactional;

import io.quarkus.scheduler.Scheduled;

@ApplicationScoped <i class="conum" data-value="1"></i><b>(1)</b>
public class TaskBean {

    @Transactional
    @Scheduled(every = "10s") <i class="conum" data-value="2"></i><b>(2)</b>
    void schedule() {
        Task task = new Task(); <i class="conum" data-value="3"></i><b>(3)</b>
        task.persist(); <i class="conum" data-value="4"></i><b>(4)</b>
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Declare the bean in the <em>application</em> scope</p>
</li>
<li>
<p>Use the <code>@Scheduled</code> annotation to instruct Quarkus to run this method every 10 seconds.</p>
</li>
<li>
<p>Create a new <code>Task</code> with the current start time.</p>
</li>
<li>
<p>Persist the task in database using <a href="https://quarkus.io/guides/hibernate-orm-panache">Panache</a>.</p>
</li>
</ol>
</div>
<div class="sect2">
<h3 id="scheduling-jobs-programmatically"><a class="anchor" href="#scheduling-jobs-programmatically"></a>Scheduling Jobs Programmatically</h3>
<div class="paragraph">
<p>It is also possible to leverage the Quartz API directly.
You can inject the underlying <code>org.quartz.Scheduler</code> in any bean:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quartz;

@ApplicationScoped
public class TaskBean {

    @Inject
    org.quartz.Scheduler quartz; <i class="conum" data-value="1"></i><b>(1)</b>

    void onStart(@Observes StartupEvent event) {
       JobDetail job = JobBuilder.newJob(MyJob.class)
                         .withIdentity("myJob", "myGroup")
                         .build();
       Trigger trigger = TriggerBuilder.newTrigger()
                            .withIdentity("myTrigger", "myGroup")
                            .startNow()
                            .withSchedule(
                               SimpleScheduleBuilder.simpleSchedule()
                                  .withIntervalInSeconds(10)
                                  .repeatForever())
                            .build();
       quartz.scheduleJob(job, trigger); <i class="conum" data-value="2"></i><b>(2)</b>
    }

    @Transactional
    void performTask() {
        Task task = new Task();
        task.persist();
    }

    // A new instance of MyJob is created by Quartz for every job execution
    public static class MyJob implements Job {

       public void execute(JobExecutionContext context) throws JobExecutionException {
          Arc.container().instance(TaskBean.class).get(). performTask(); <i class="conum" data-value="3"></i><b>(3)</b>
       }

    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Inject the underlying <code>org.quartz.Scheduler</code> instance.</p>
</li>
<li>
<p>Schedule a new job using the Quartz API.</p>
</li>
<li>
<p>Lookup the bean instance of <code>TaskBean</code> and invoke the <code>performTask()</code> method from the job.</p>
</li>
</ol>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
By default, the scheduler is not started unless a <code>@Scheduled</code> business method is found. You may need to force the start of the scheduler for "pure" programmatic scheduling. See also <a href="#quartz-configuration-reference">Quartz Configuration Reference</a>.
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="updating-the-application-configuration-file"><a class="anchor" href="#updating-the-application-configuration-file"></a>Updating the application configuration file</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Edit the <code>application.properties</code> file and add the below configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs"># Quartz configuration
quarkus.quartz.clustered=true <i class="conum" data-value="1"></i><b>(1)</b>
quarkus.quartz.store-type=jdbc-cmt <i class="conum" data-value="2"></i><b>(2)</b>

# Datasource configuration.
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=quarkus_test
quarkus.datasource.password=quarkus_test
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test

# Hibernate configuration
quarkus.hibernate-orm.database.generation=none
quarkus.hibernate-orm.log.sql=true
quarkus.hibernate-orm.sql-load-script=no-file

# flyway configuration
quarkus.flyway.connect-retries=10
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.migrate-at-start=true
quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.baseline-version=1.0
quarkus.flyway.baseline-description=Quartz</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Indicate that the scheduler will be run in clustered mode</p>
</li>
<li>
<p>Use the database store to persist job related information so that they can be shared between nodes</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="updating-the-resource-and-the-test"><a class="anchor" href="#updating-the-resource-and-the-test"></a>Updating the resource and the test</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Edit the <code>TaskResource</code> class, and update the content to:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quartz;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/tasks")
@Produces(MediaType.APPLICATION_JSON)
public class TaskResource {

    @GET
    public List&lt;Task&gt; listAll() {
        return Task.listAll(); <i class="conum" data-value="1"></i><b>(1)</b>
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Retrieve the list of created tasks from the database</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>We also need to update the tests. Edit the <code>TaskResourceTest</code> class to match:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quartz;

import io.quarkus.test.junit.QuarkusTest;

import static org.hamcrest.Matchers.greaterThanOrEqualTo;

import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class TaskResourceTest {

    @Test
    public void tasks() throws InterruptedException {
        Thread.sleep(1000); // wait at least a second to have the first task created
        given()
                .when().get("/tasks")
                .then()
                .statusCode(200)
                .body("size()", is(greaterThanOrEqualTo(1))); <i class="conum" data-value="1"></i><b>(1)</b>
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Ensure that we have a <code>200</code> response and at least one task created</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-quartz-tables"><a class="anchor" href="#creating-quartz-tables"></a>Creating Quartz Tables</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Add a SQL migration file named <code>src/main/resources/db/migration/V2.0.0__QuarkusQuartzTasks.sql</code> with the content copied from
file with the content from <a href="https://github.com/quarkusio/quarkus-quickstarts/blob/master/quartz-quickstart/src/main/resources/db/migration/V2.0.0__QuarkusQuartzTasks.sql">V2.0.0__QuarkusQuartzTasks.sql</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-the-load-balancer"><a class="anchor" href="#configuring-the-load-balancer"></a>Configuring the load balancer</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In the root directory, create a <code>nginx.conf</code> file with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="conf" class="language-conf hljs">user  nginx;

events {
    worker_connections   1000;
}

http {
        server {
              listen 8080;
              location / {
                proxy_pass http://tasks:8080; <i class="conum" data-value="1"></i><b>(1)</b>
              }
        }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Route all traffic to our tasks application</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="setting-application-deployment"><a class="anchor" href="#setting-application-deployment"></a>Setting Application Deployment</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In the root directory, create a <code>docker-compose.yml</code> file with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="yaml" class="language-yaml hljs">version: '3'

services:
  tasks: <i class="conum" data-value="1"></i><b>(1)</b>
    image: quarkus-quickstarts/quartz:1.0
    build:
      context: ./
      dockerfile: src/main/docker/Dockerfile.${QUARKUS_MODE:-jvm}
    environment:
      QUARKUS_DATASOURCE_URL: jdbc:postgresql://postgres/quarkus_test
    networks:
      - tasks-network
    depends_on:
      - postgres

  nginx: <i class="conum" data-value="2"></i><b>(2)</b>
    image: nginx:1.17.6
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - tasks
    ports:
      - 8080:8080
    networks:
      - tasks-network

  postgres: <i class="conum" data-value="3"></i><b>(3)</b>
    image: postgres:11.3
    container_name: quarkus_test
    environment:
      - POSTGRES_USER=quarkus_test
      - POSTGRES_PASSWORD=quarkus_test
      - POSTGRES_DB=quarkus_test
    ports:
      - 5432:5432
    networks:
      - tasks-network

networks:
  tasks-network:
    driver: bridge</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Define the tasks service</p>
</li>
<li>
<p>Define the nginx load balancer to route incoming traffic to an appropriate node</p>
</li>
<li>
<p>Define the configuration to run the database</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="running-the-database"><a class="anchor" href="#running-the-database"></a>Running the database</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In a separate terminal, run the below command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">docker-compose up postgres <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Start the database instance using the configuration options supplied in the <code>docker-compose.yml</code> file</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="run-the-application-in-dev-mode"><a class="anchor" href="#run-the-application-in-dev-mode"></a>Run the application in Dev Mode</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Run the application with: <code>./mvnw quarkus:dev</code>.
After a few seconds, open another terminal and run <code>curl localhost:8080/tasks</code> to verify that we have at least one task created.</p>
</div>
<div class="paragraph">
<p>As usual, the application can be packaged using <code>./mvnw clean package</code> and executed using the <code>-runner.jar</code> file.
You can also generate the native executable with <code>./mvnw clean package -Pnative</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="packaging-the-application-and-run-several-instances"><a class="anchor" href="#packaging-the-application-and-run-several-instances"></a>Packaging the application and run several instances</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The application can be packaged using <code>./mvnw clean package</code>. Once the build is successful, run the below command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">docker-compose up --scale tasks=2 --scale nginx=1 <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Start two instances of the application and a load balancer</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>After a few seconds, in another terminal, run <code>curl localhost:8080/tasks</code> to verify that tasks were only created at different instants and in an interval of 10 seconds.</p>
</div>
<div class="paragraph">
<p>You can also generate the native executable with <code>./mvnw clean package -Pnative</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quartz-register-plugin-listeners"><a class="anchor" href="#quartz-register-plugin-listeners"></a>Registering Plugin and Listeners</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can register a plugin, jobListener or triggerListener through Quarkus configuration.</p>
</div>
<div class="paragraph">
<p>The example bellow registers the plugin <code>org.quartz.plugins.history.LoggingJobHistoryPlugin</code> named as <code>jobHistory</code> with the property <code>jobSuccessMessage</code> defined as <code>Job [{1}.{0}] execution complete and reports: {8}</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="conf" class="language-conf hljs">quarkus.quartz.plugin.jobHistory.class=org.quartz.plugins.history.LoggingJobHistoryPlugin
quarkus.quartz.plugin.jobHistory.jobSuccessMessage=Job [{1}.{0}] execution complete and reports: {8}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also register a listener programmatically with an injected <code>org.quartz.Scheduler</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">---
public class MyListenerManager {
    void onStart(@Observes StartupEvent event, org.quartz.Scheduler scheduler) throws SchedulerException {
        scheduler.getListenerManager().addJobListener(new MyJogListener());
        scheduler.getListenerManager().addTriggerListener(new MyTriggerListener());
    }
}
---</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quartz-configuration-reference"><a class="anchor" href="#quartz-configuration-reference"></a>Quartz Configuration Reference</h2>
<div class="sectionbody">
<div class="paragraph configuration-legend">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> Configuration property fixed at build time - All other configuration properties are overridable at runtime</p>
</div>
<table class="tableblock frame-all grid-all stretch configuration-reference searchable">
<colgroup>
<col style="width: 80%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock"><a id="quarkus-quartz_configuration"></a><a href="#quarkus-quartz_configuration">Configuration property</a></p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Type</p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Default</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.clustered"></a><code><a href="#quarkus-quartz_quarkus.quartz.clustered">quarkus.quartz.clustered</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Enable cluster mode or not.
 If enabled make sure to set the appropriate cluster properties.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>false</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.store-type"></a><code><a href="#quarkus-quartz_quarkus.quartz.store-type">quarkus.quartz.store-type</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The type of store to use.
 When using the <code>db</code> store type configuration value make sure that you have the datasource configured. See <a href="https://quarkus.io/guides/datasource">Configuring your datasource</a> for more information.
 To create Quartz tables, you can perform a schema migration via the <a href="https://quarkus.io/guides/flyway">Flyway extension</a> using a SQL script matching your database picked from <a href="https://github.com/quartz-scheduler/quartz/blob/master/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore">Quartz repository</a>.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>ram</code>, <code>jdbc-tx</code>, <code>jdbc-cmt</code>, <code>db</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>ram</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.datasource"></a><code><a href="#quarkus-quartz_quarkus.quartz.datasource">quarkus.quartz.datasource</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The name of the datasource to use.
 Optionally needed when using the <code>db</code> store type. If not specified, defaults to using the default datasource.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.table-prefix"></a><code><a href="#quarkus-quartz_quarkus.quartz.table-prefix">quarkus.quartz.table-prefix</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The prefix for quartz job store tables.
 Ignored if using a <code>ram</code> store.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>QRTZ_</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-quartz_quarkus.quartz.thread-count"></a><code><a href="#quarkus-quartz_quarkus.quartz.thread-count">quarkus.quartz.thread-count</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The size of scheduler thread pool. This will initialize the number of worker threads in the pool.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">int</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>25</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-quartz_quarkus.quartz.thread-priority"></a><code><a href="#quarkus-quartz_quarkus.quartz.thread-priority">quarkus.quartz.thread-priority</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Thread priority of worker threads in the pool.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">int</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>5</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-quartz_quarkus.quartz.force-start"></a><code><a href="#quarkus-quartz_quarkus.quartz.force-start">quarkus.quartz.force-start</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>By default, the scheduler is not started unless a <code>io.quarkus.scheduler.Scheduled</code> business method is found. If set to true the scheduler will be started even if no scheduled business methods are found. This is necessary for "pure" programmatic scheduling.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>false</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.triggerlistener.-namedtriggerlistener-.class"></a><code><a href="#quarkus-quartz_quarkus.quartz.triggerlistener.-namedtriggerlistener-.class">quarkus.quartz.triggerListener."namedTriggerListener".class</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Class name for the configuration.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.triggerlistener.-namedtriggerlistener-propsandvalue"></a><code><a href="#quarkus-quartz_quarkus.quartz.triggerlistener.-namedtriggerlistener-propsandvalue">quarkus.quartz.triggerListener."namedTriggerListener"</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The props name and the values for the props.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Map&lt;String,String&gt;</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.joblistener.-namedjoblistener-.class"></a><code><a href="#quarkus-quartz_quarkus.quartz.joblistener.-namedjoblistener-.class">quarkus.quartz.jobListener."namedJobListener".class</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Class name for the configuration.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.joblistener.-namedjoblistener-propsandvalue"></a><code><a href="#quarkus-quartz_quarkus.quartz.joblistener.-namedjoblistener-propsandvalue">quarkus.quartz.jobListener."namedJobListener"</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The props name and the values for the props.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Map&lt;String,String&gt;</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.plugin.-namedplugin-.class"></a><code><a href="#quarkus-quartz_quarkus.quartz.plugin.-namedplugin-.class">quarkus.quartz.plugin."namedPlugin".class</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Class name for the configuration.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-quartz_quarkus.quartz.plugin.-namedplugin-propsandvalue"></a><code><a href="#quarkus-quartz_quarkus.quartz.plugin.-namedplugin-propsandvalue">quarkus.quartz.plugin."namedPlugin"</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The props name and the values for the props.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Map&lt;String,String&gt;</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
